package com.hy.study.driver;

import com.hy.study.bean.OrderBean;
import com.hy.study.mapper.OrderMapper;
import com.hy.study.order.OrderGroupingComparator;
import com.hy.study.reduce.OrderReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * 获取一个订单中价格最大的值
 *
 * @author huyong
 * @date 2024 年 02 月 05 日 17:49: 06
 */
public class OrderDriver {
    public static void main(String[] args) throws Exception {
        final String inputfile = "./input/groupcomparator";
        final String outputfile = "./output/result3";
        Job job = Job.getInstance(new Configuration());

        job.setMapperClass(OrderMapper.class);
        job.setReducerClass(OrderReducer.class);

        job.setMapOutputKeyClass(OrderBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(OrderBean.class);
        job.setOutputValueClass(NullWritable.class);

        job.setJarByClass(OrderDriver.class);

        //指定分组类
        job.setGroupingComparatorClass(OrderGroupingComparator.class);
        FileInputFormat.addInputPath(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        boolean completion = job.waitForCompletion(true);
        System.exit(completion ? 0 : 1);

    }
}
